package com.example.hm_dtfkz.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import com.android.base.util.ActivityClickUtil;
import com.android.base.util.DisplayUtil;
import com.android.base.util.ToastUtil;
import com.example.hm_dtfkz.R;
import com.example.hm_dtfkz.databinding.DialogIndulgeTipBinding;
import com.example.hm_dtfkz.databinding.DialogRealNameBinding;

public class DialogRealName extends Dialog implements View.OnClickListener{

    private DialogRealNameBinding binding;
    private final Activity activity;
    private  int times=1;

    public DialogRealName(Activity a) {
        super(a, R.style.dialog_loading);
        this.activity = a;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DialogRealNameBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = DisplayUtil.getScreenWidth(activity);
        lp.height = DisplayUtil.getScreenHeight(activity);
        getWindow().setAttributes(lp);

        setCancelable(false);
        setCanceledOnTouchOutside(false);
        initView();
        initLister();
    }

    private void initView() {
        ActivityClickUtil.getInstance().clear();

    }

    private void initLister() {
        binding.imgClose.setOnClickListener(this);
        binding.tvSubmit.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (ActivityClickUtil.getInstance().isFastClick()) {
            //防止用户快速点击
            return;
        }

        if (v.getId() == R.id.imgClose) {
            dismiss();
        } else  if (v.getId() == R.id.tv_submit) {
            if(binding.edname.getText().length()>4){
                ToastUtil.showShortToastCenter(activity,"信息验证有误");
                return;
            }
            if(binding.edQQ.getText().length()!=16){
                ToastUtil.showShortToastCenter(activity,"身份证信息验证有误");
                return;
            }

            if(times<3){
                ToastUtil.showShortToastCenter(activity,"信息验证有误");
                times++;
            }else {
                ToastUtil.showShortToastCenter(activity,"实名认证成功");
                dismiss();
            }
        }

    }
}
